package com.thunder.kocho.loki;

import android.animation.Animator;
import android.graphics.Rect;
import android.view.animation.LinearInterpolator;

import com.thunder.kocho.loki.builder.KeyFrameAnimatorBuilder;
import com.thunder.kocho.loki.shape.CircleLoki;

import java.util.ArrayList;

public class TripleCircle extends LokiGroup{

    @Override
    protected ArrayList<Loki> onCreateChild() {
        ArrayList<Loki> lokis=new ArrayList<>();
        for(int i=0;i<3;i++){
            Loki loki=new TripleCircleLoki();
            loki.setAnimationDelays(300*i);
            lokis.add(loki);
        }
        return lokis;
    }

    @Override
    protected void onBoundsChange(Rect bounds) {
        super.onBoundsChange(bounds);
        bounds=clipSquare(bounds);
        int side=bounds.width()/3;
        for(int i=0;i<3;i++){
            Loki loki=getChildAt(i);
            loki.setLokiBoundsAndPivot(bounds.left+side*i,bounds.top+side,bounds.left+side*i+side,bounds.top+side*2);
            if(loki instanceof CircleLoki){
                ((CircleLoki) loki).setRadius(side/2);
            }
        }
    }

    @Override
    protected void onChildCreated(ArrayList<Loki> lokis) {

    }

    private static class TripleCircleLoki extends CircleLoki{

        @Override
        protected Animator onCreateAnimator() {
            return new KeyFrameAnimatorBuilder()
                    .scale(new float[]{0f,0.5f,1f},1f,0.65f,1f)
                    .alpha(new float[]{0f,0.5f,1f},255,100,255)
                    .count(-1)
                    .duration(1000)
                    .interpolator(new LinearInterpolator())
                    .target(this)
                    .build();
        }
    }
}
